<?php
    require_once("condb.php");
    require_once("functions.php");
    
    $OpType = OpType();
    
    $output = array();
    $info = isset($_GET["info"]) ? $_GET["info"] : "";
    if(!empty($info)){
        $info = urldecode(base64_decode($info));
        parse_str($info, $request);    
        
        $token = isset($request["token"]) ? cleanQuery($request["token"]) : "";
        if($token=="TAoViEC@)!#2012"){
            $data = array();
            
            $data["appId"] = isset($request["appId"]) ? intval($request["appId"]) : 0;            
            $data["branch"] = isset($request["branch"]) ? cleanQuery($request["branch"]) : "";
            $data["handset"] = isset($request["handset"]) ? cleanQuery($request["handset"]) : "";
            $data["w"] = isset($request["w"]) ? cleanQuery($request["w"]) : "";
            $data["h"] = isset($request["h"]) ? cleanQuery($request["h"]) : "";
            $data["midp"] = isset($request["midp"]) ? cleanQuery($request["midp"]) : "";
            
            $os = isset($request["operation_system"]) ? cleanQuery($request["operation_system"]) : "";    
            $os = strtolower($os);
            $data["os_type"] = isset($OpType[$os]) ? $OpType[$os] : 0;
            $data["operation_system"] = $os;
            
            $data["type_content"] = isset($request["type_content"]) ? intval($request["type_content"]) : 0;                        
            
            if(!empty($data["appId"]) && !empty($data["type_content"])){
                $result = UpdateApplicationView($data);
                if($result){
                    $output["status"] = 1;
                    $output["msg"] = "Success Request";    
                } else {
                    $output["status"] = 0;
                    $output["msg"] = "Failed Request";
                }                
            } else {
                $output["status"] = 4;
                $output["msg"] = "Invalid Request";                        
            }
                
        } else {
            $output["status"] = 3;
            $output["msg"] = "Invalid Request";    
        }
    } else {
        $output["status"] = 2;
        $output["msg"] = "Invalid Request";
    }                         
    
    echo json_encode($output);  
?>